pmf

We can use the base plot functions in R to create a plot of the pmf for a binomial random variable \(X\) with \(n=13\) and \(p=0.6\) — i.e. \(X\ \tilde \ B(13,\ 0.6)\).

  n <- 13
  p <- 0.6
  x <- -1:14
  pmf <- dbinom(x, n, p)
  plot(x, pmf, type="h", xlab="x", ylab="p = P(X=x)", main="X~B(13, 0.6)", ylim=c(0, 0.25), xaxt="n")
  axis(1,at=seq(0,14,by=2))
  text(x, pmf+0.005, round(pmf, digits=4), cex=0.6)

CDF

The CDF may be plotted analogously.

  x <- -1:15
  cdf <- pbinom(x, n, p)
  plot(x, cdf, type="s", xlab="x", ylab="P(X<=c)", main="X~B(13, 0.6)", xaxt="n")
  axis(1, at=seq(0,14,by=2))

Just for fun we can overlay the two.

    pmf <- dbinom(x, n, p)
  plot(x, pmf, type="h", xlab="x", ylab="p", main="X~B(13, 0.6)", ylim=c(0, 1), xaxt="n", col="red", lty=3)
    lines(x, cdf, type="s", xlab="x", ylab="P(X<=c)", main="X~B(13, 0.6)", xaxt="n")
  axis(1,at=seq(0,14,by=2))